#!/bin/bash
typeAction=$1
typeBack=$2
if [ ! $typeAction ]
  then
    typeAction="linux"
elif [ $typeAction == "windows" ]
  then
    typeAction="windows"
elif [ $typeAction == "mac" ]
  then
    typeAction="darwin"
fi

# zhi
cd ./engine || exit
go mod tidy

cd ../lib || exit
go mod tidy

# 打包 cms
cd ../cms || exit
go env -w GOARCH=amd64 GOOS=$typeAction
go mod tidy
go build -o ../build/cms main.go

if [ ! $typeBack ]
  then
    typeBack="darwin"
fi

if /usr/bin/arch -arm64e /usr/bin/true 2>/dev/null; then
  echo "Apple Silicon 芯片"
  go env -w GOARCH=arm64 GOOS=$typeBack
else
  echo "非 Apple Silicon 芯片"
  go env -w GOARCH=amd64 GOOS=$typeBack
fi
echo "打包完成"